﻿using System;
using System.Windows.Forms;

namespace MyMovies
{
    public partial class credentialForm : Form
    {
        public credentialForm()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            txtUser.Text = Properties.Settings.Default.Username;
            txtPass.Text = Properties.Settings.Default.Password == string.Empty
                                ? Properties.Settings.Default.Password
                                : Cryption.Decrypt(Properties.Settings.Default.Password);
            ckbMemorize.Checked = Properties.Settings.Default.Memorize;
            base.OnLoad(e);
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.Username = txtUser.Text;
            Properties.Settings.Default.Password = Cryption.Encrypt(txtPass.Text);
            Properties.Settings.Default.Memorize = ckbMemorize.Checked;

            //if (!ckbMemorize.Checked)
            //{
            //    Properties.Settings.Default.Username = string.Empty;
            //    Properties.Settings.Default.Password = string.Empty;
            //    Properties.Settings.Default.Memorize = false;
            //}

            if (ckbMemorize.Checked)
                Properties.Settings.Default.Save();
        }
    }
}